package com.example.androidhw02_1;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.nfc.Tag;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.BaseAdapter;

public class MyAdapter extends BaseAdapter {
	//implements WordListView.OnWordClickListener 

	public static final int ITEM_VIEW_TYPE_TAG=0;
	public static final int ITEM_VIEW_TYPE_WORD=1;
	public static final int ITEM_VIEW_COUNT=2;
	
	List<TagAndWords> mList;
	Context mContext;

//	public interface OnItemViewClickListener {
//		public void onItemViewClick(Adapter a, View v, WordListView data);
//	}
//
//	OnItemViewClickListener mListener;
//
//	public void setOnItemViewClickListener(OnItemViewClickListener listener) {
//		mListener = listener;
//	}

	public MyAdapter(Context context, ArrayList<TagAndWords> list) {
		// TODO Auto-generated constructor stub
		mContext = context;
		mList = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		TagAndWords data = mList.get(position);

		if (data.bool == false) {
			WordListView itemView;
			if (convertView == null) {
				itemView = new WordListView(mContext);
//				itemView.setOnWordClickListener(this);
			} else {
				itemView = (WordListView) convertView;
			}
			itemView.setData(data);
			return itemView;
		} else {
			TagView itemView;
			if (convertView == null) {
				itemView = new TagView(mContext);
			} else {
				itemView = (TagView) convertView;
			}
			itemView.setData(data);
			return itemView;
		}
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		TagAndWords data = mList.get(position);
		if (data.bool == true) {
			return ITEM_VIEW_TYPE_TAG;
		} else {
			return ITEM_VIEW_TYPE_WORD;
		}
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return ITEM_VIEW_COUNT;
	}

	public void add(TagAndWords myData) {
		// TODO Auto-generated method stub
		mList.add(myData);
		notifyDataSetChanged();
	}

//	@Override
//	public void onWordClick(View v, WordListView data) {
//		// TODO Auto-generated method stub
//		if (mListener != null) {
//			mListener.onItemViewClick(this, v, data);
//		}
//	}
}
